Why can't I overwrite the prototype of `Array` (`Array.prototype`)?
Posted
by
user828896
on Stack Overflow
See other posts from Stack Overflow
or by user828896
Published on 2012-10-10T02:53:24Z
Indexed on
2012/10/10
3:37 UTC
Read the original article
Hit count: 132
JavaScript
I set the prototype of Array
as an instance of my
, I think book.aa
will display "aa"
, but it displays "undefined"
, why? Thanks!
<html>
<head>
<title>Array Properties</title>
<h2>Array Properties</h2>
<script type="text/javascript">
function my() {
this.aa = 'aa';
}
Array.prototype = new my();
Array.prototype.bb = "bb";
var book = new Array();
book[0] = "War and Peace";
</script>
</head>
<body bgcolor="lightblue">
<script type="text/javascript">
document.write(book.aa+book.bb);
</script>
</body>
</html>
© Stack Overflow or respective owner